from django.db import models

# Create your models here.


class Staff(models.Model):
    username = models.CharField(max_length=10, null=False)
    password = models.CharField(max_length=20, null=False)
    name = models.CharField(max_length=10, null=False)
    position = models.CharField(max_length=10, null=False)
    annualLeave = models.IntegerField(null=True)
    department = models.CharField(max_length=20, null=True)

    def __str__(self):
        return self.name

    def to_json(self):
        fields = []
        for field in self._meta.fields:
            fields.append(field.name)

        d = {}
        for attr in fields:
            d[attr] = getattr(self, attr)

        import json
        return json.dumps(d, ensure_ascii=False)
